package com.freshcity.page.friend
{
	import com.freshcity.component.container.Component;
	import com.freshcity.core.Dispatcher;
	import com.freshcity.core.GlobalVar;
	import com.freshcity.core.OpCodes;
	import com.freshcity.friend.InfoWin;
	import com.freshcity.lib.event.DataEvent;
	import com.freshcity.lib.event.EventName;
	import com.freshcity.manager.EffectManager;
	import com.freshcity.utils.StringUtil;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	public class InfoPanel extends Component
	{
		public var home:FriendHome;
		private var back:InfoWin;
		private var txtFormat:TextFormat;
		private var infoPanel:Sprite;
		private var ypos:Number;
		
		public function InfoPanel(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			txtFormat = new TextFormat("宋体", 12);
			txtFormat.leading = 6;
			super(parent, xpos, ypos);
		}
		
		override protected function addChildren():void
		{
			super.addChildren();
			back = new InfoWin();
			addChild(back);
		}
		
		override public function destroy():void
		{
			super.destroy();
		}
		
		override public function show(event:Event=null):void
		{
			infoPanel = new Sprite();
			infoPanel.mouseEnabled = false;			
			ypos = 10;
			
			var user:String=home.asso.id;
			Dispatcher.addEventListener(EventName.UserReadDone,showUserInfo);
			main.findUser(user);
			super.show(event);
		}
		
		private function showUserInfo(evt:DataEvent):void
		{
			Dispatcher.removeEventListener(EventName.UserReadDone,showUserInfo);
			EffectManager.hideLoadMask();
			var data:* = evt.data;
			
			var len:int=GlobalVar.nameProperty.length;
			var mine:Object = main.user;
			var xpos:Number = 0.0;
			var j:int = 0;
			
			createTitleLabel("基础资料：");
			
			for (var i:int=0; i < len; i++)
			{
				var s1:String=GlobalVar.nameProperty[i];
				var s2:String=GlobalVar.labelProperty[i];
				if (mine[s1] && data.user[s1])
				{
					if(j%2==0){
						xpos = 55;
						ypos += 25;
					}else{
						xpos = 300;
					}
					createProperty(s2, data.user[s1],xpos,ypos);
					j++;
				}
			}
			
			ypos += 30;
			createUserDesc(data.user.selfDesc); //自我描述
			back.panel.source = infoPanel;
		}
		
		private function createUserDesc(data:String):void
		{
			createTitleLabel("交友独白：");
			ypos += 25;
			
			var contentTf:TextField=new TextField();
			contentTf.defaultTextFormat = txtFormat;
			contentTf.autoSize=TextFormatAlign.LEFT;
			contentTf.text = data;
			contentTf.width=380;
			contentTf.wordWrap=true;
			contentTf.x = 50;
			contentTf.y = ypos;
			infoPanel.addChild(contentTf);
			
		}
		
		private function createTitleLabel(label:String):void
		{
			var labelTf:TextField=new TextField();
			labelTf.defaultTextFormat = new TextFormat("黑体", 14);
			labelTf.autoSize=TextFormatAlign.LEFT;
			labelTf.text = label;
			labelTf.x = 45;
			labelTf.y = ypos;
			infoPanel.addChild(labelTf);
		}
		
		private function createProperty(label:String,value:String,xpos:Number=0,ypos:Number=0):void
		{
			var tf:TextField=new TextField();
			tf.defaultTextFormat = txtFormat;
			tf.autoSize=TextFormatAlign.LEFT;
			tf.height=20;
			tf.width=180;
			tf.htmlText = StringUtil.addColor(label + " ", "#666666") + value;
			tf.x = xpos;
			tf.y = ypos;
			infoPanel.addChild(tf);
		}
	}
}